package com.bocai.eelly.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * TimeUtils
 * 
 * @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-8-24
 */
public class TimeUtils {

    public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final SimpleDateFormat DATE_FORMAT_DATE    = new SimpleDateFormat("yyyy-MM-dd");
    public static final SimpleDateFormat DATE_FORMAT_DATE_NOYEAR    = new SimpleDateFormat("MM-dd HH:mm");
    public static final SimpleDateFormat DATE_FORMAT_DATE_NOYEAR_CHINA    = new SimpleDateFormat("MM月dd日 HH:mm");
    public static final SimpleDateFormat DATE_FORMAT_DATE_CHINA=new SimpleDateFormat("yyyy年MM月dd日");
    public static final SimpleDateFormat DATE_MONTH=new SimpleDateFormat("MM.dd");

    private TimeUtils() {
        throw new AssertionError();
    }


    /**
     * 掉此方法输入所要转换的时间输入例如（"2014-06-14"）返回时间戳
     *
     * @param time
     * @return
     */
    public static String dataOne(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);
        Date date;
        String times = null;
        try {
            date = sdr.parse(time);
            long l = date.getTime();
            String stf = String.valueOf(l);
            times = stf.substring(0, 10);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return times;
    }
    public static String getMonth(long timeInMillis) {
        return getTime(timeInMillis, DATE_MONTH);
    }
    /**
     * long time to string
     * 
     * @param timeInMillis
     * @param dateFormat
     * @return
     */
    public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
        return dateFormat.format(new Date(timeInMillis*1000L));
    }

    /**
     * long time to string, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @param timeInMillis
     * @return
     */
    public static String getTime(long timeInMillis) {
        return getTime(timeInMillis, DATE_FORMAT_DATE_NOYEAR);
    }

    /**
     *
     * @param timeInMillis
     * @return
     */
    public static String getTime_china(long timeInMillis) {
        return getTime(timeInMillis, DATE_FORMAT_DATE_NOYEAR_CHINA);
    }
    /**
     *
     * @param timeInMillis
     * @return
     */
    public static String getTime_year_month_data(long timeInMillis) {
        return getTime(timeInMillis, DATE_FORMAT_DATE_NOYEAR_CHINA);
    }
    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static long getCurrentTimeInLong() {
        return System.currentTimeMillis();
    }

    /**
     * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @return
     */
    public static String getCurrentTimeInString() {
        return getTime(getCurrentTimeInLong());
    }

    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
        return getTime(getCurrentTimeInLong(), dateFormat);
    }
}
